<template>
  <ul class="" :class="isSingleDrug?'form-normal-base-componet':'common-form'">
    <li v-for="(item, index) in formDate" :key="index">
      <van-failed v-if="item.type==='Text'" :label="item.label" :placeholder="item.placeholder"
                  :modelName="item.name" @sendValue="sendValue" :value="submitInfo[item.name]"
                  :readonly="isSingleDrug" :type="item.type" :isDisabled="isDisabled"></van-failed>
      <vant-date-picker v-if="item.type==='Date'" :label="item.label" :modelName="item.name" :minDate="item.minDate"
                        :maxDate="item.maxDate" :defaultValue="item.defaultValue" :mode="item.mode" :type="item.type"
                        :placeholder="item.placeholder" @sendValue="sendValue"
                        :value="submitInfo[item.name]" :isLink="isSingleDrug"
                        :isDisabled="isDisabled"></vant-date-picker>
      <expect-child-calculator v-if="item.name==='expectChildBirth'&&!isDisabled" :name="item.name"
                               :isLink="isSingleDrug" :type="item.type"
                               @sendValue="sendValue" :isDisabled="isDisabled"></expect-child-calculator>
      <van-divider v-if="item.name==='expectChildBirth'&&isSingleDrug" />
      <vant-picker v-if="item.type==='Picker'"
                   :modelName="item.name"
                   :label="item.label"
                   :maxNum="item.maxNum"
                   :minNum="item.minNum"
                   :unit="item.unit"
                   :defaultValue="item.defaultValue"
                   :placeholder="item.placeholder"
                   :isLink="isSingleDrug"
                   :value="submitInfo[item.name]"
                   :type="item.type" :isDisabled="isDisabled"
                   @sendValue="sendValue"
      >
      </vant-picker>
    </li>
  </ul>
</template>

<script>
import VanFailed from "./VanFailed";
import VantDatePicker from "./VantDatePicker";
import VantPicker from "./VantPicker";
import ExpectChildCalculator from "./ExpectChildCalculator";
import { Divider } from "vant";
import { formatTime } from "../common/utils/time";

export default {
  name: "UpdateBaseInfo",
  components: {
    [Divider.name]: Divider,
    VanFailed,
    VantDatePicker,
    VantPicker,
    ExpectChildCalculator
  },
  props: {
    registerInfo: {
      type: Object,
      default: () => {
      }
    },
    baseInfo: {
      type: Array,
      default: () => []
    },
    // 是否是普通单元格  普通是一行展示  不普通是两行展示
    isSingleDrug: {
      type: Boolean,
      default: false
    },
    isDisabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formDate: this.baseInfo,
      submitInfo: this.registerInfo
    };
  },
  created() {
  },
  methods: {
    sendValue(res) {
      this.submitInfo[res.name] = res.value;
      this.$emit("sendValue", res);
    }
  }
};
</script>

<style scoped lang="less">
.van-divider--hairline {
  width: 750px;
  height: 15px;
  background: #F9FAFD;
  margin: 0 0 0 -30px;
}

.van-divider--hairline::before {
  display: none;
}
</style>
